package com.engine4cloud.tdf.common.core.util.preview;

import java.net.URI;
import java.net.URISyntaxException;
import java.util.HashMap;
import java.util.Map;

public class FileNameExtractorUtils {
    public static String extract(String url) {
        String result = "";
        try {
            URI uri = new URI(url);
            Map<String, String> queryParams = new HashMap<>();
            for (String param : uri.getRawQuery().split("&")) {
                String[] pair = param.split("=");
                if (pair.length > 1) {
                    queryParams.put(pair[0], pair[1]);
                } else {
                    queryParams.put(pair[0], "");
                }
            }

            result = queryParams.get("fileName");
        } catch (URISyntaxException e) {
            e.printStackTrace();
        }
        return result;
    }
}
